#include "LogLevel.h"
#include <string.h>

namespace log
{


std::string LogLevel::toString(LogLevel::ELevel eLevel)
{
    switch (eLevel)
    {
#define XX(str) \
    case LogLevel::ELevel::str: \
        return #str;

        XX(TRACE)
        XX(DEBUG)
        XX(INFO)
        XX(WARN)
        XX(ERROR)
    }
#undef XX

    return "";
}

LogLevel::ELevel LogLevel::fromString(const std::string& str)
{
#define XX(eLevel) \
    if (::memcmp(str.c_str(), #eLevel, str.length()) == 0) \
    { \
        return LogLevel::ELevel::eLevel; \
    }

        XX(TRACE)
        XX(DEBUG)
        XX(INFO)
        XX(WARN)
        XX(ERROR)

#undef XX
    return LogLevel::ELevel::INFO;
}
    
std::ostream& operator<<(std::ostream& os, log::LogLevel::ELevel eLevel)
{
    os << LogLevel::toString(eLevel);
    return os;
}

} // namespace log
